import {AfterViewInit, Component, OnInit, ViewChild} from "@angular/core";
import {HeroChildComponent} from "../hero-child/hero-child";
import {MissionService} from "../../service/mission.service";

/**
 * Created by ZE-C on 2017/8/12.
 */

@Component({
  selector: 'hero-parent',
  template: `
  <div class="z-box">
    parent
    <button (click)="confirmChild()">parent btn confirm child</button>
    <hero-child ></hero-child>
    
    <!--<hero-child ></hero-child>-->
    <!--<button (click)="child.childFunc(parent_para)">parent btn to do child func</button>-->
    <!--<label>i get the child's name: {{child.childName}}</label>-->
    
<!--    &lt;!&ndash;<button (click)="changeName()">changeme</button>
    <hero-child (onVoted)="changeName($event)"></hero-child>&ndash;&gt;


    &lt;!&ndash; <button (click)="changeName()">btn</button>
        <hero-child [name]="name" [age]="age"></hero-child>&ndash;&gt;

    &lt;!&ndash; <hero-child *ngFor="let i of heros" [name]="i"></hero-child>&ndash;&gt;

    &lt;!&ndash;<ul>
      <li style="color: antiquewhite" *ngFor="let i of heros">abc {{i}}</li>
    </ul>&ndash;&gt;

    &lt;!&ndash;<hero-child *ngFor="let i of heros" [index]="i"></hero-child>&ndash;&gt;-->
  </div>
  `,
  styleUrls: []
})
export class HeroParentComponent{

  mes = 'parent para';

  constructor(private missionService:MissionService){

  }

  confirmChild(){
    this.mes += 'hi ';
    this.missionService.publish(this.mes)
  }


/*  constructor(){
    console.log('parent: constructor()')
  }

  ngOnInit(): void {
    console.log('parent: ngOnInit(): '+ (this.child.childName || 'none') )
  }


  ngAfterViewInit(): void {
    console.log('parent: ngAfterViewInit(): '+ (this.child.childName || 'none') )

    this.child.childFunc('')
  }


  @ViewChild(HeroChildComponent)
    child:HeroChildComponent;*/

  // parent_para = 'i am parent paras';

/*  name = 'init';

  changeName($event) {

    console.log(`parent: parent.changeName(${$event})`)

    /!*this.name += 'a '
     this.age += 1*!/
  }*/

  /*  heros = [1,2,3]
   name = 'initial_name'
   age = 18

   changeName(){
   this.name += 'a '
   this.age += 1
   }*/
  _id = 0;
}




